#include <bits/stdc++.h>
using namespace std;

// 定义图的邻接表表示
int a[1000000][1000000];
int visited[1 << 22];

int main() {
  int H, W;
  cin >> H >> W;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> a[i][j];
    }
  }

  queue<int> q;

  q.push(0);
  visited[0] = 1;

  while (!q.empty()) {
    // 取出队首节点
    int fa = q.front();
    q.pop();

    for (int i = 0; i < H - 1; i++) {
      for (int j = 0; j < W; j++) {

        if (fa & ((1 << W + 1) << (i * W + j)))
          continue;
        int son = fa + (1 << W + 1) << (i * W + j);
        if (visited[son] == 0) {
          q.push(son);
          visited[son] = 1;
        }
      }
    }

    for (int i = 0; i < H - 1; i++) {
      for (int j = 0; j < W - 1; j++) {

        int son = fa + 3 << (i * W + j);
        if (visited[son] == 0) {
          q.push(son);
          visited[son] = 1;
        }
      }
    }
  }
  int leizhu = 0;
  for (int i = 0; i < (1 << (H * W)); i++) {
    int ans = 0;
    if (visited[i] == 1) {
      for (int j = 0; j < H; j++) {
        for (int k = 0; k < W; k++) {
          if (i & (1 << (j * W + k) == 0)) {
            ans = ans ^ a[j][k];
          }
        }
      }
    }
    leizhu = min(leizhu, ans);
  }
  cout << leizhu;

  return 0;
}
